//
//  DropViewController.m
//  UILbrary
//
//  Created by Apple on 2022/5/8.
//  Copyright © 2022 mac. All rights reserved.
//

#import "DropViewController.h"
#import "JXSecondHandDropViewHandle.h"
#import "JXSelectViewHandle.h"

@interface DropViewController ()<JXSecondHandDropViewHandleDelegate>
@property (nonatomic, strong) JXSecondHandDropViewHandle *dropVieHandle;
@end

@implementation DropViewController

- (void)dealloc
{
    NSLog(@"DropViewController-dealloc");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self test];
}

- (void)test
{
    [self test_1];
}

- (void)test_1
{
    JXSecondHandDropViewDataSouce *data_1 = [JXSecondHandDropViewDataSouce new];
    data_1.title = @"品牌";
    data_1.selectArr = [self selectModels:[self brandArr]];

    JXSecondHandDropViewDataSouce *data_2 = [JXSecondHandDropViewDataSouce new];
    data_2.title = @"价位";
    data_2.selectArr = [self selectModels:[self priceArr]];
    
    JXSecondHandDropViewDataSouce *data_3 = [JXSecondHandDropViewDataSouce new];
    data_3.title = @"车龄";
    data_3.selectArr = [self selectModels:[self ageArr]];
    
    JXSecondHandDropViewDataSouce *data_4 = [JXSecondHandDropViewDataSouce new];
    data_4.title = @"车龄地区";
    data_4.selectArr = [self selectModels:[self areArr]];

    
    NSArray *dataSource = @[data_1,data_2,data_3,data_4];
    self.dropVieHandle = [[JXSecondHandDropViewHandle alloc] initWithDatas:dataSource onView:self.view delegate:self];
    
    [self.view addSubview:self.dropVieHandle.view];
    
    [self.dropVieHandle.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).offset(100);
        make.left.right.mas_equalTo(self.view);
        make.height.mas_equalTo(25);
    }];
}


//MARK: - JXSecondHandDropViewHandleDelegate

- (void)JXSecondHandDropViewHandle:(JXSecondHandDropViewHandle *)handle selectModelList:(NSArray <JXSecondHandDropViewSelectModel *> *)selectModelList
{
    [selectModelList enumerateObjectsUsingBlock:^(JXSecondHandDropViewSelectModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *title = obj.title.length > 0  ? obj.title : @"空";
        NSString *selectStatus = obj.isSelect ? @"选中" : @"未选中";
        NSString *string = [NSString stringWithFormat:@"%@_第%ld个 %@",title,obj.idx,selectStatus];
        NSLog(@"%@",string);
    }];
}

- (NSArray <JXSecondHandDropViewSelectModel *>*)selectModels:(NSArray <NSString *>*)datas
{
    NSMutableArray *mutableArr = [@[] mutableCopy];
    [datas enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        JXSecondHandDropViewSelectModel *model = [JXSecondHandDropViewSelectModel new];
        model.title = obj;
        model.idx = idx;
        [mutableArr addObject:model];
    }];
    return [mutableArr copy];
}

- (NSArray <NSString *>*)brandArr
{
    return [self arrWithCount:20 title:@"品牌"];
}

- (NSArray <NSString *>*)arrWithCount:(NSInteger )count title:(NSString *)title
{
    NSMutableArray *mutableArr = [@[] mutableCopy];
    for (NSInteger i=0; i<count; i++) {
        NSString *brand = [NSString stringWithFormat:@"%@_%ld",title,i];
        [mutableArr addObject:brand];
    }
    return [mutableArr copy];
}

- (NSArray <NSString *>*)priceArr
{
    return [self arrWithCount:10 title:@"价位"];
}

- (NSArray <NSString *>*)ageArr
{
    return [self arrWithCount:5 title:@"车龄"];
}

- (NSArray <NSString *>*)areArr
{
    return [self arrWithCount:50 title:@"地区"];
}

//MARK: - get



@end
